package com.haohuo.question2;

import java.util.List;

/**
 * 测试方法
 * note：
 * <p>
 * author: Caozhitong
 **/
public class Test {

    public static void main(String[] args) {

        // 根据题目中的图，构建一个有向无环图，如下：
        String[] vertexLabels = new String[]{"A", "B", "C", "D", "E", "F", "G"};
        Vertex[] vertices = new Vertex[vertexLabels.length];
        for (int i = 0; i < vertexLabels.length; i++) {
            vertices[i] = new Vertex(vertexLabels[i]);
        }
        NoRingGraph noRingGraph = new NoRingGraph(vertices);

        noRingGraph.addEdge(0, 1)        // A -> B
                .addEdge(0, 2)     // A -> C
                .addEdge(1, 3)     // B -> D
                .addEdge(2, 5)     // C -> F
                .addEdge(3, 4)     // D -> E
                .addEdge(4, 5)     // E -> F
                .addEdge(3, 6)     // D -> G
                .addEdge(5, 6);    // F -> G

        // 遍历图的所有的拓扑序列，即为最终的结果
        List<List<Vertex>> topologicalOrder = noRingGraph.getTopologicalOrder();
        if (null == topologicalOrder) {
            System.out.println("处理不了");
        } else {
            for (List<Vertex> vertexList : topologicalOrder) {
                System.out.println(vertexList);
            }
        }
    }


}
